pull: Copy the upstream summary file when doing a pull --mirror
authorColin Walters <walters@verbum.org>
Wed, 4 Feb 2015 19:49:22 +0000 (14:49 -0500)
committerColin Walters <walters@verbum.org>
Fri, 6 Feb 2015 02:24:21 +0000 (21:24 -0500)
While it could be regenerated downstream, there might be other
metadata upstream, and the goal here is a mirror.

https://bugzilla.gnome.org/show_bug.cgi?id=739377

src/libostree/ostree-repo-pull.c
tests/test-pull-mirror-summary.sh

index fd19d687edf763ade84f7c3d41fdf30128073472..d3e228c4dd69b9ace7aa4f26b83d3d45ea62e96a 100644 (file)
@@ -58,6 +58,7 @@ typedef struct {
   
   gboolean          gpg_verify;
 
+  GBytes           *summary_data;
   GVariant         *summary;
   GPtrArray        *static_delta_superblocks;
   GHashTable       *expected_commit_sizes; /* Maps commit checksum to known size */
@@ -1864,6 +1865,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
           gs_unref_variant GVariant *refs = NULL;
           gsize i, n;
 
+          pull_data->summary_data = g_bytes_ref (bytes);
           pull_data->summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes, FALSE);
           refs = g_variant_get_child_value (pull_data->summary, 0);
           n = g_variant_n_children (refs);
@@ -1886,6 +1888,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
                        "Fetching all refs was requested in mirror mode, but remote repository does not have a summary");
           goto out;
         }
+
     } 
   else if (refs_to_fetch != NULL)
     {
@@ -2061,6 +2064,14 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
         }
     }
 
+  if (pull_data->is_mirror && pull_data->summary_data)
+    {
+      if (!ot_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary",
+                                        pull_data->summary_data, !pull_data->repo->disable_fsync,
+                                        cancellable, error))
+        goto out;
+    }
+
   if (!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error))
     goto out;
 
@@ -2127,6 +2138,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
   g_free (pull_data->remote_name);
   if (pull_data->base_uri)
     soup_uri_free (pull_data->base_uri);
+  g_clear_pointer (&pull_data->summary_data, (GDestroyNotify) g_bytes_unref);
   g_clear_pointer (&pull_data->summary, (GDestroyNotify) g_variant_unref);
   g_clear_pointer (&pull_data->static_delta_superblocks, (GDestroyNotify) g_ptr_array_unref);
   g_clear_pointer (&pull_data->commit_to_depth, (GDestroyNotify) g_hash_table_unref);
index a09b152c78db74c5f6b641182d7ac1781da2f11b..2a8a293d56d81cd995fd4cac839e2ee49c988b39 100755 (executable)
@@ -41,6 +41,7 @@ mkdir repo
 ostree --repo=repo init --mode=archive-z2
 ostree --repo=repo remote add --set=gpg-verify=false origin $(cat httpd-address)/ostree/gnomerepo
 ostree --repo=repo pull --mirror origin
+assert_has_file repo/summary
 ostree --repo=repo checkout -U main main-copy
 assert_file_has_content main-copy/baz/cow "moo"
 ostree --repo=repo checkout -U other other-copy